package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ArticleService;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.mess.UpdateArticleMess;
import com.heima.model.wemedia.dtos.WmUpdateCommentDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {
    @Autowired
    private ArticleService articleService;
    /**
     * 修改评论状态
     * @param dto
     */
    @Override
    public void updateCommentStatus(WmUpdateCommentDto dto) {
        if (dto.getOperation().equals(0)) {
            //关闭评论
            update(Wrappers.<ApArticleConfig>lambdaUpdate().eq(ApArticleConfig::getArticleId,dto.getArticleId())
                    .set(ApArticleConfig::getIsComment,false));
            //将文章表的评论数量置为0
            articleService.update(Wrappers.<ApArticle>lambdaUpdate().eq(ApArticle::getId,dto.getArticleId())
                    .set(ApArticle::getComment,0));
        }else
            //打开评论
            update(Wrappers.<ApArticleConfig>lambdaUpdate().eq(ApArticleConfig::getArticleId,dto.getArticleId())
                    .set(ApArticleConfig::getIsComment,true));
    }
}
